package flappy.bird.cover.ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import flappy.bird.cover.resource.AppResource;

public class Main extends MIDlet implements CommandListener {
	private Display display;
	private GameUI gameUI;
	private Command cmdExit;
	// BirdAct bird;
	Menu menu;

	public Main() {
		display = Display.getDisplay(this);
		cmdExit = new Command("Exit", Command.EXIT, 1);

		// Create game canvas and exit command
		// if ((gameUI = new GameUI()) != null) {
		// gameUI.addCommand(cmdExit);
		// gameUI.setCommandListener(this);
		// }
		// if ((bird = new BirdAct()) != null) {
		// bird.addCommand(cmdExit);
		// bird.setCommandListener(this);
		// }
		if ((menu = new Menu(this)) != null) {
			menu.addCommand(cmdExit);
			menu.setCommandListener(this);
		}
	}

	protected void destroyApp(boolean unconditional)
			throws MIDletStateChangeException {
		// gameUI.stop();
		// bird.stop();
		// menu.stop();
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// if (gameUI != null) {
		// new AppResource().loadLevel();
		// display.setCurrent(gameUI);
		// gameUI.start();
		// }
		// if (bird != null) {
		// new AppResource().loadLevel();
		// display.setCurrent(bird);
		// bird.start();
		// }
		if (menu != null) {
			new AppResource().loadLevel();
			display.setCurrent(menu);
			menu.start();
		}
	}

	public void commandAction(Command c, Displayable d) {
		if (c == cmdExit) {
			try {
				destroyApp(true);
			} catch (MIDletStateChangeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			notifyDestroyed();

		}
	}

	public Display getDisplay() {
		return Display.getDisplay(this);
	}
}
